<?php
namespace My\Controller;

use Utuo\BackgroundController;

class ModuleDialController extends BackgroundController {
	
	// 初始化
	public function _initialize() {
		$this->setControllerTitle('一键拨号管理');
		$this->setActionTitle(array(
			 'index' => '一键拨号设置',
		));
	}
	
	// 一键拨号设置
	public function indexAction(){
		$m = M("ModuleDial");
		if(!$m->where(array('id'=>$this->aid))->count()){
			if(!$m->add(array(
				'id' => $this->aid
			))){
				$this->error("创建一键拨号失败");
			}
		}
		$moduleDial = $m->find($this->aid);
		$this->assign("moduleDial",$moduleDial);
		$this->display();
	}
	
	// 一键拨号设置提交
	public function indexPostAction(){
		$d = M('ModuleDial');
		if ($d->create()) {
			$d->id = $this->aid;
			if (false !== $d->save()) {
				$this->ajaxSuccess('修改一键拨号成功');
			} else {
				$this->ajaxError($d->getError());
			}
		} else {
			$this->ajaxError($d->getError());
		}
		$this->display();
	}
	
}